﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Event.UI;
using CPPEI.Coolzon.Service.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class RespUpdateClientStatusHandler : BaseResponseHandler<RespUpdateClientStatusData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, 
            ServiceProxy.MainServiceRef.Response response, RespUpdateClientStatusData responseData)
        {
            NCLClientStatusChangedEvent @event = new NCLClientStatusChangedEvent(responseData.UserIdentity,
                responseData.UserAccount,
                responseData.UserName,
                responseData.Status);
            NCLEventBus.PublishAsync(@event);

            if(responseData.Status == ClientStatus.Normal)
            {
                UIEventBus.PublishAsync(new UIEnableInteractiveEvent());
            }
            else
            {
                if (responseData.Status == ClientStatus.Loading)
                {
                    UIEventBus.PublishAsync(new UIDisableInteractiveEvent("正在等待终端加载方案"));
                    CheckClientStatusThread.Start("正在等待终端加载方案");
                }
                else
                {
                    UIEventBus.PublishAsync(new UIDisableInteractiveEvent("正在等待终端同步状态"));
                    CheckClientStatusThread.Start("正在等待终端同步状态");
                }
            }
        }
    }
}
